package com.mq.test.config.mq.listener;

import com.rabbitmq.client.Channel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.listener.api.ChannelAwareMessageListener;
import org.springframework.stereotype.Component;

@Component
public class MQConsumeListener implements ChannelAwareMessageListener {
    private static Logger logger = LoggerFactory.getLogger(MQConsumeListener.class);


    @Override
    public void onMessage(Message message, Channel channel) throws Exception {
        logger.info(message.getMessageProperties().getConsumerQueue());
        logger.info(message.toString());
        channel.basicQos(1);
        channel.basicAck(message.getMessageProperties().getDeliveryTag(),true);// deliveryTag the tag from the received,可以理解为channel的标识
        //channel.basicNack(100L,false,false);
    }
}
